$(function () {
    var token = sessionStorage.getItem("token");
    var method = "Plan|lists";
    var pagesize = "6";
    jhMore();
    var p = 1;
    var i = 1;
    $(".jh-btn").click(function () {
        p += 1;
        $(this).attr("disabled", "disabled");
        setTimeout(function () {
            $(".jh-btn").removeAttr("disabled");
        }, 2000);
        jhMore(p);
    })
    $("#to-sx").click(function () {
        i++;
        if (i % 2 == 0) {
            $("#sx").show();
            var d = {};
            d.token = token;
            d.method = "bankcredit|card_list";
            $.ajax({
                type: "post",
                url: "http://www.rice.com/app/api/h5_access",
                data: d,
                dataType: "json",
                success: function (result) {
                    if (result.status == "1") {
                        var sttr = "";
                        var data = result.data;
                        for (var i in data) {
                            sttr += '<li style="cursor:pointer;" onclick="javascript:sxClick(this);" data-type="' + data[i].bankcredit_id + '"><span>' + data[i].cardAfterFour + '</span></li>';
                        }
                        $("#sx").html(sttr);

                    }

                }
            })
        } else {
            $("#sx").hide();
        }

    })

    function jhMore(p, t) {
        if (!p) {
            p = "1";
        }
        if (!t) {
            t = "all";
        }
        var d = {};
        d.token = token;
        d.method = method;
        d.p = p + "";
        d.pagesize = pagesize;
        d.bank_credit_id = t;
        $.ajax({
            type: "post",
            url: "http://www.rice.com/app/api/h5_access",
            data: d,
            dataType: "json",
            success: function (result) {
                if (result.status == "1") {
                    var data = result.data.plan_data;
                    var sttr = $(".jhb-xq").html();
                    for (var i in data) {
                        sttr += '<div style="padding: 5px 0 5px 0;cursor: pointer" class="am-u-sm-12 jhb" data-id="' + data[i].plan_id + '"><div class="am-u-sm-12" style="background: #fff;padding: 5px 10px 0px 10px;border-top:1px solid #E3E2E6 ;"><div class="am-u-sm-6" style="font-size: 15px ;">计划单号</div>';
                        sttr += '<div class="am-u-sm-6" style="font-size: 15px ;color: #5BADF1;text-align: right;">' + data[i].status_name + '</div><div style="font-size: 14px;">' + data[i].order_no + '</div></div>';
                        sttr += '<div class="am-u-sm-12" style="background: #fff;padding: 0px 10px 8px 10px;border-bottom: 1px solid #E3E2E6;"><div class="am-u-sm-7" style="font-size: 15px ;">' + data[i].section + '</div>';
                        sttr += '<div class="am-u-sm-5" style="font-size: 18px ;color: #333;text-align: right;font-weight: bold;">' + data[i].money + '</div></div></div>';
                    }
                    $(".jhb-xq").html(sttr);
                    $(".jhb").click(function () {
                        var plan_id = $(this).attr("data-id");
                        sessionStorage.setItem("plan_id", plan_id);
                        location.href = "paymentplan.html";
                    })
                } else if (result.status == "2") {
                    alert(result.message);
                    location.href = "login.html";
                } else {
                    alert(result.message);
                }
            }
        })
    }
})
var token = sessionStorage.getItem("token");
var method = "Plan|lists";
var pagesize = "6";

function sxClick(obj) {
    var type = $(obj).attr("data-type");
    $('.More').attr("data-type", type);
    zdmore(1, type);
};

function zdmore(p, t) {
    if (!p) {
        p = "1";
    }
    if (!t) {
        t = "all";
    }
    var d = {};
    d.token = token;
    d.method = method;
    d.p = p + "";
    d.pagesize = pagesize;
    d.bank_credit_id = t;
    console.log(d);
    $.ajax({
        type: "post",
        url: "http://www.rice.com/app/api/h5_access",
        data: d,
        dataType: "json",
        success: function (result) {
            if (result.status == "1") {
                console.log(result);
                var data = result.data.plan_data;
                var sttr = "";
                for (var i in data) {
                    console.log(data[i]);
                    sttr += '<div style="padding: 5px 0 5px 0;cursor: pointer" class="am-u-sm-12 jhb" data-id="' + data[i].plan_id + '"><div class="am-u-sm-12" style="background: #fff;padding: 5px 10px 0px 10px;border-top:1px solid #E3E2E6 ;"><div class="am-u-sm-6" style="font-size: 15px ;">计划单号</div>';
                    sttr += '<div class="am-u-sm-6" style="font-size: 15px ;color: #5BADF1;text-align: right;">' + data[i].status_name + '</div><div style="font-size: 14px;">' + data[i].order_no + '</div></div>';
                    sttr += '<div class="am-u-sm-12" style="background: #fff;padding: 0px 10px 8px 10px;border-bottom: 1px solid #E3E2E6;"><div class="am-u-sm-7" style="font-size: 15px ;">' + data[i].section + '</div>';
                    sttr += '<div class="am-u-sm-5" style="font-size: 18px ;color: #333;text-align: right;font-weight: bold;">' + data[i].money + '</div></div></div>';
                }
                $(".jhb-xq").html(sttr);
                $(".jhb").click(function () {
                    var plan_id = $(this).attr("data-id");
                    sessionStorage.setItem("plan_id", plan_id);
                    location.href = "paymentplan.html";
                })
            } else if (result.status == "2") {
                alert(result.message);
                location.href = "login.html";
            } else {
                alert(result.message);
            }
        }
    })
}